<template>
    <div style="margin: 10px 10px 0px 0px">
<template>

  <el-tabs type="border-card" @tab-click="tablick" >
    <el-tab-pane label="新增公告">
      <template v-if="tabindex==0">
        <!-- 新增公告的组件 -->
     <newword></newword>
    </template>
    </el-tab-pane>
    <el-tab-pane label="草稿箱" style="height: 100%;">
      <template v-if="tabindex==1">
       <nocitecompont :index="0"> </nocitecompont>
      </template>
    </el-tab-pane>
    <el-tab-pane label="已发布"  style="height: 100%;"> 
      <template v-if="tabindex==2">
        <nocitecompont :index="1"> </nocitecompont>
      </template>
    </el-tab-pane>
    <el-tab-pane label="已删除"  style="height: 100%;">
      <template v-if="tabindex==3">
        <nocitecompont :index="2"> </nocitecompont>
      </template>
    
    </el-tab-pane>
  </el-tabs>
</template>



       
      
      
    </div>
  </template>
  <script>
    // 1 导入需要使用的组件
    import nocitecompont from '../components/nocite.vue'
    import newword from '../views/newword.vue'
     export default{
      components: {
        nocitecompont,
        newword
  },


      data(){
        return{
            dialogFormVisible:false,
            title:"",
            value1: '',
            formLabelWidth:"120",
            tableData: [],
        form:{"name":"222"},
        noticestatus:'',
        tabindex:''
        }
      },

      created(){

      },
      methods:{

    

     

    
        // 查询按钮
        onSubmit(){
            console.log(this.title)
            console.log("888")
            var time=""
         if(this.value1){
             time= this.timestampToTime(this.value1,1);
         }
         
    
  console.log(time)
  

     this.axios({
             url:this.$api+'/notice/selectByTileAndTime', 
             dataType:"json",
            method:'get',
            params: {
                title:this.title,
                time:time

            },
            }).then((res)=>{
                var list=[]
                if(res.data){
                for(var i=0;i<res.data.length;i++){
                    var item={}
                    var str=res.data[i]
                    console.log(str)
                    item.id=str.id,
                    item.person=str.person,
                    item.time=str. time,
                    item.title=str.title ,
                    item.content=str.content
                    list.push(item)
                }
         this.tableData=list

                }

            }).catch((res)=>{

            })





        },
        //    新增公告
        addonSubmit(){
                //编辑和新增为一个模态框 新增的状态为1 编辑的状态为2
                var url="hckdv"
            var text1=""
            var text2=""
            var params={}
            let nowTime = this.timestampToTime(new Date(),2)
            if(this.noticestatus==1){
            url="/notice/insertNotice"
            text1="新增公告"
            text2="添加成功" 
             params={
                
                title:this.form.title,
                content:this.form.content,
                person:this.form.person,
                time:nowTime
            }
                    
           }else{
            url="/notice/updateNotice"
            text1="修改公告信息"
            text2="修改成功"
           params={
                 id:this.form.id,
                title:this.form.title,
                content:this.form.content,
                person:this.form.person,
                time:nowTime
            }
           }

    
          
  
           this.$confirm('是否确定提交表单', '确认信息', {
          distinguishCancelAndClose: true,
          confirmButtonText: '提交',
          cancelButtonText: '取消'
        }).then((res)=>{
            this.axios({
             url:this.$api+url, 
             dataType:"json",
            //  String title,String content,String time,String person
            params:params
            }).then((res)=>{
                console.log(res)
                this.$message({
          message: text2,
          type: 'success'
        })   
        this.dialogFormVisible=false
     
        this.noticeinfolist()

            }).catch((res)=>{

            })

        }).catch((res)=>{})


     
            


        },

        //日期格式

        timestampToTime(times,num) {
     //num是判断是否返回时分秒 num=1为不传时分秒 num=2返回时分秒
    times=times.toLocaleString('en-US',{hour12: false}).split(" ")
    let time = times[1]
    let mdy = times[0]
    mdy = mdy.split('/')
    let month = parseInt(mdy[0]);
    let day = parseInt(mdy[1]);
    let year = parseInt(mdy[2])
    if(month<10){
        console.log(month)
        month="0"+month
      
    }
    if(day<10){
        day="0"+day
    }

    //是否传回时分秒 num=1为不传时分秒 num=2返回时分秒
  if(num==1){
    return  year + '-' + month + '-' + day 
  }
  else{
    return  year + '-' + month + '-' + day + ' ' + time
  }
 
   

},


        handleEdit(index,item){
            this.dialogFormVisible=true
            this.noticestatus=index
            if(index==1){
                this.form={}
            }else{
                this.form=item
            }
           
            
        





        },
            //点击选项卡
        tablick(e){
          console.log("点击选项卡")
           console.log(e.index)
          this.tabindex=e.index

//           if(e.index==0){
//             this.$router.push("/index/notice/newword")
//           }else{
//             this.$router.push(`/index/notice/nocitelist/${e.index-1}`, (res)=>{

// console.log("成功")
// }, (res)=>{
// console.log("失败")
// })  

//           }

   

        },

        handleDelete(id){
            this.$confirm('此删除为永久删除 是否确认删除', '确认信息', {
          distinguishCancelAndClose: true,
          confirmButtonText: '提交',
          cancelButtonText: '取消'
        }).then((res)=>{
            this.axios({
             url:this.$api+"/notice/deleteNotice", 
             dataType:"json",
            params:{
                 id:id
            }
            }).then((res)=>{
                console.log(res)
                this.$message({
          message: "删除成功",
          type: 'success'
        })   
        this.noticeinfolist()

            }).catch((res)=>{

            })

        }).catch((res)=>{})

        },
      }
     }
  </script>
  <style>

  </style>